﻿@using DTcms.Common;
@{
    ViewBag.Title = "在线留言管理";
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">插件管理</a> </li>
            <li><a href="javascript:;">在线留言</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAudit" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-survey"></i><span> 审核</span></a>
                            <a data-type="btnDelete" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="iconfont icon-delete"></i><span> 删除</span></a>
                            <a class="layui-btn icon-btn layui-btn-normal layui-btn-sm" href="../feedback/feedback_install"><i class="fa fa-cog"></i><span> 配置</span></a>
                        </div>
                        <div class="menu-select">
                            <select class="select" lay-filter="btnSearch" name="ddlSiteId" url="/webapi/siteJson" selectValue="" promtion="所有站点"><option value="">所有站点...</option></select>
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'title', templet:'#title'}">标题</th>
                        <th lay-data="{field:'siteTitle'}">所属站点</th>
                        <th lay-data="{field:'user_name'}">用户</th>
                        <th lay-data="{field:'add_time'}">发布时间</th>
                        <th lay-data="{field:'type',templet: '#type'}">类型</th>
                        <th lay-data="{field:'is_lock', templet:'#switchTpl'}">审核状态</th>
                        <th lay-data="{field:'reply_content', templet:'#reply'}">回复状态</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="title">
    <a href="../feedback/feedback_edit?id={{d.id}}" class="layui-table-link">{{d.title}}{{d.is_lock == 1 ? '(未审核)' : ''}}</a>
</script>
<script type="text/html" id="type">
    <span class="layui-btn  layui-btn-xs{{d.type==1?' layui-btn-normal':' layui-btn-danger'}}">{{d.type==1?'建议':'投诉'}}</span>
</script>
<script type="text/html" id="reply">
    {{d.reply_content == "" ? '未回复' : '已回复'}}
</script>
<script type="text/html" id="barDemo">
    <a href="../feedback/feedback_edit?action=@DTEnums.ActionEnum.Edit&id={{d.id}}" class="layui-btn layui-btn-xs"><i class="fa fa-edit"></i> 回复留言</a>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="通过|不通过" lay-filter="lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table', 'cascadeSelect', 'cmswh'], function () {
            var table = layui.table, form = layui.form, cascadeSelect = layui.cascadeSelect, cmswh = layui.cmswh, $ = layui.jquery;
            cascadeSelect.init('ddlSiteId', false);
            cmswh.dataBind('FeedbackList');

            //监听状态操作
            form.on('switch(lock)', function (obj) {
                cmswh.request("FeedbackLock", "POST", { id: this.value, is_lock: obj.elem.checked });
            });
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            var active = {
                btnDelete: function () {
                    cmswh.batOperate('FeedbackDelete', 'id');
                },
                btnAudit: function () {
                    cmswh.batOperate('FeedbackAudit', 'id');
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var siteId = $("select[name=ddlSiteId]").val();
                var postdata = { keywords: keywords, _site_id: siteId };
                return postdata;
            }
        });
    </script>
}